package io.gitee.chearnee.fw.datasecurity.core.handler.desensitization;

import io.gitee.chearnee.fw.datasecurity.core.annotation.desensitization.SDNumField;
import org.springframework.util.StringUtils;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 11/9/2022 5:13 PM
 */
public class SDNumRuleHandler implements SDRuleHandler<SDNumField> {
    public SDNumRuleHandler() {
        //init
    }

    @Override
    public Class<SDNumField> getAnnotationType() {
        return SDNumField.class;
    }

    @Override
    public String masking(SDNumField t, String object) {
        return processing(t, object);
    }

    private String processing(SDNumField t, String object) {
        //region 先依照示例来脱敏
        if (StringUtils.hasText(t.eg())) {
            return baseEgMasking(t.eg(), t.mask(), object);
        }
        //endregion
        return baseMasking(t.firstShow(), t.lastShow(), t.mask(), object);
    }
}
